package Presentation;

import BusinessLogic.*;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import javax.swing.*;
import javax.swing.text.*;

public class frmGroupChat extends javax.swing.JFrame {
    String username;
    String state;
    public DefaultListModel model = new DefaultListModel();
    frmInvite invite;
    static frmClient client;
    
    public frmGroupChat() {
        initComponents();
        this.setLocation(350, 100);
        setIcon();
        tf_message.requestFocusInWindow();
        ls_users.setModel(model);
        AutoSmiles.initListener(tp_log);
    }
    
    public frmGroupChat(String groupname, frmClient frm) {
        initComponents();
        this.setLocation(350, 100);
        setIcon();
        tf_message.requestFocusInWindow();
        setGroup(groupname);
        ls_users.setModel(model);
        client=frm;
        AutoSmiles.initListener(tp_log);
    }
    
    private void setIcon() {
        setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/Images/icon.png")));
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tp_log = new javax.swing.JTextPane();
        jPanel3 = new javax.swing.JPanel();
        btn_Send = new javax.swing.JButton();
        tf_message = new javax.swing.JTextField();
        cbo_font = new javax.swing.JComboBox();
        cbo_size = new javax.swing.JComboBox();
        btn_B = new javax.swing.JToggleButton();
        btn_I = new javax.swing.JToggleButton();
        btn_U = new javax.swing.JToggleButton();
        jLabel4 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        ls_users = new javax.swing.JList();
        jLabel2 = new javax.swing.JLabel();
        btn_Invite = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        lb_groupname = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        mn_hoithoai = new javax.swing.JMenu();
        mni_New = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        mni_Close = new javax.swing.JMenuItem();
        mn_chucnang = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        mn_Help = new javax.swing.JMenu();
        mni_Info = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setBackground(new java.awt.Color(204, 204, 255));
        setName("frm_khungchat"); // NOI18N
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        tp_log.setEditable(false);
        tp_log.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jScrollPane1.setViewportView(tp_log);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 241, Short.MAX_VALUE)
        );

        jPanel3.setBackground(new java.awt.Color(204, 204, 255));

        btn_Send.setBackground(new java.awt.Color(204, 204, 255));
        btn_Send.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
        btn_Send.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/Comment.png"))); // NOI18N
        btn_Send.setBorder(null);
        btn_Send.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        btn_Send.setName("btn_send"); // NOI18N
        btn_Send.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                btn_SendMouseEntered(evt);
            }
        });
        btn_Send.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_SendActionPerformed(evt);
            }
        });

        tf_message.setFont(new java.awt.Font("Times New Roman", 0, 13)); // NOI18N
        tf_message.setBorder(BorderFactory.createCompoundBorder(
            tf_message.getBorder(), 
            BorderFactory.createEmptyBorder(0, 5, 0, 0)));
    tf_message.addInputMethodListener(new java.awt.event.InputMethodListener() {
        public void caretPositionChanged(java.awt.event.InputMethodEvent evt) {
        }
        public void inputMethodTextChanged(java.awt.event.InputMethodEvent evt) {
            tf_messageInputMethodTextChanged(evt);
        }
    });
    tf_message.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyPressed(java.awt.event.KeyEvent evt) {
            tf_messageKeyPressed(evt);
        }
    });

    javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
            .addContainerGap(15, Short.MAX_VALUE)
            .addComponent(tf_message, javax.swing.GroupLayout.PREFERRED_SIZE, 360, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGap(12, 12, 12)
            .addComponent(btn_Send, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap())
    );
    jPanel3Layout.setVerticalGroup(
        jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel3Layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addComponent(btn_Send, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE))
                .addComponent(tf_message))
            .addContainerGap())
    );

    cbo_font.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Arial", "Times New Roman", "Tahoma", "Verdana", " " }));
    cbo_font.setName("cb_font"); // NOI18N
    cbo_font.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseEntered(java.awt.event.MouseEvent evt) {
            cbo_fontMouseEntered(evt);
        }
    });
    cbo_font.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            cbo_fontActionPerformed(evt);
        }
    });

    cbo_size.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", " " }));
    cbo_size.setSelectedIndex(6);
    cbo_size.setName("cb_size"); // NOI18N
    cbo_size.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseEntered(java.awt.event.MouseEvent evt) {
            cbo_sizeMouseEntered(evt);
        }
    });

    btn_B.setText("B");
    btn_B.setBorder(null);
    btn_B.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    btn_B.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseEntered(java.awt.event.MouseEvent evt) {
            btn_BMouseEntered(evt);
        }
    });

    btn_I.setText("I");
    btn_I.setBorder(null);
    btn_I.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    btn_I.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseEntered(java.awt.event.MouseEvent evt) {
            btn_IMouseEntered(evt);
        }
    });

    btn_U.setText("U");
    btn_U.setBorder(null);
    btn_U.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    btn_U.addMouseListener(new java.awt.event.MouseAdapter() {
        public void mouseEntered(java.awt.event.MouseEvent evt) {
            btn_UMouseEntered(evt);
        }
    });

    jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/style.png"))); // NOI18N

    ls_users.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
    ls_users.setName("ls_users"); // NOI18N
    jScrollPane2.setViewportView(ls_users);

    jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 48)); // NOI18N
    jLabel2.setForeground(new java.awt.Color(255, 51, 51));
    jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    jLabel2.setText(" G_IT");

    btn_Invite.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/group.png"))); // NOI18N
    btn_Invite.setText("Mời bạn");
    btn_Invite.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            btn_InviteActionPerformed(evt);
        }
    });

    javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
    jPanel4.setLayout(jPanel4Layout);
    jPanel4Layout.setHorizontalGroup(
        jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel4Layout.createSequentialGroup()
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(btn_Invite))
                .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 159, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
            .addContainerGap())
    );
    jPanel4Layout.setVerticalGroup(
        jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(jPanel4Layout.createSequentialGroup()
            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(btn_Invite)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(22, Short.MAX_VALUE))
    );

    jLabel1.setText("Nhóm chat: ");

    lb_groupname.setFont(new java.awt.Font("Times New Roman", 1, 12)); // NOI18N

    jMenuBar1.setForeground(new java.awt.Color(0, 153, 153));

    mn_hoithoai.setText("Hội thoại");

    mni_New.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
    mni_New.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/new_message.png"))); // NOI18N
    mni_New.setText("Mới");
    mni_New.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            mni_NewActionPerformed(evt);
        }
    });
    mn_hoithoai.add(mni_New);
    mn_hoithoai.add(jSeparator1);

    mni_Close.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
    mni_Close.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/close_window.png"))); // NOI18N
    mni_Close.setText("Đóng");
    mni_Close.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            mni_CloseActionPerformed(evt);
        }
    });
    mn_hoithoai.add(mni_Close);

    jMenuBar1.add(mn_hoithoai);

    mn_chucnang.setText("Chức năng");

    jMenuItem1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/group_add.png"))); // NOI18N
    jMenuItem1.setText("Mời bạn");
    mn_chucnang.add(jMenuItem1);

    jMenuItem2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/group_delete.png"))); // NOI18N
    jMenuItem2.setText("Xóa nhóm");
    mn_chucnang.add(jMenuItem2);

    jMenuBar1.add(mn_chucnang);

    mn_Help.setText("Trợ giúp");

    mni_Info.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H, java.awt.event.InputEvent.CTRL_MASK));
    mni_Info.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/house.png"))); // NOI18N
    mni_Info.setText("Thông tin");
    mni_Info.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            mni_InfoActionPerformed(evt);
        }
    });
    mn_Help.add(mni_Info);

    jMenuBar1.add(mn_Help);

    setJMenuBar(jMenuBar1);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(btn_B, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(14, 14, 14)
                    .addComponent(btn_I, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(btn_U, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(cbo_font, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addComponent(cbo_size, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(8, 8, 8)))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        .addGroup(layout.createSequentialGroup()
            .addGap(20, 20, 20)
            .addComponent(jLabel1)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(lb_groupname, javax.swing.GroupLayout.PREFERRED_SIZE, 276, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(lb_groupname, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGap(18, 18, 18)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cbo_font, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbo_size, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btn_U, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btn_I, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(btn_B, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(8, 8, 8)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addContainerGap())
    );

    pack();
    }// </editor-fold>//GEN-END:initComponents

    
    private void btn_SendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_SendActionPerformed
        if(!tf_message.getText().equals("")){
            String style=getStyle();
            myMessage(tf_message.getText());
            Connection.sendData(Command.MESSAGE_SEND_GROUP+style+username+(char)(001)+lb_groupname.getText()+(char)(002)+tf_message.getText());
            tf_message.setText("");
            tf_message.requestFocus();
        }
    }//GEN-LAST:event_btn_SendActionPerformed
    private void cbo_fontActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbo_fontActionPerformed
        
    }//GEN-LAST:event_cbo_fontActionPerformed
    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened

    }//GEN-LAST:event_formWindowOpened

    private void mni_CloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mni_CloseActionPerformed
       Object[] option = {"Đồng ý", "Hủy bỏ"};
        int dialogResult = JOptionPane.showOptionDialog(this, "Bạn có chắc chắn muốn thoát khỏi nhóm này?", "",JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE,null,option,option[0]);
        if(dialogResult==0){
            Connection.sendData(Command.LEAVE_GROUP+username+((char)001)+lb_groupname.getText());
            this.dispose();
        }
    }//GEN-LAST:event_mni_CloseActionPerformed
    private void mni_InfoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mni_InfoActionPerformed
        JOptionPane.showMessageDialog(null, "- Chương trình Chat Application\n-  Version: 1.0\n- Nhóm thực hiện: G_IT\n- Khoa CNTT & TT đại học Cần Thơ 2013");
    }//GEN-LAST:event_mni_InfoActionPerformed

private void tf_messageKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tf_messageKeyPressed
    if(evt.getKeyCode() == KeyEvent.VK_ENTER){
       btn_SendActionPerformed(null);
    }
}//GEN-LAST:event_tf_messageKeyPressed

private void btn_BMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_BMouseEntered
    btn_B.setToolTipText("In đậm");
}//GEN-LAST:event_btn_BMouseEntered

private void btn_IMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_IMouseEntered
    btn_I.setToolTipText("In nghiêng");
}//GEN-LAST:event_btn_IMouseEntered

private void btn_UMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_UMouseEntered
    btn_U.setToolTipText("Gạch chân");
}//GEN-LAST:event_btn_UMouseEntered

private void cbo_fontMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbo_fontMouseEntered
    cbo_font.setToolTipText("Chọn font chữ");
}//GEN-LAST:event_cbo_fontMouseEntered

private void cbo_sizeMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cbo_sizeMouseEntered
    cbo_size.setToolTipText("Kích cỡ chữ");
}//GEN-LAST:event_cbo_sizeMouseEntered

private void btn_SendMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_SendMouseEntered
    btn_Send.setToolTipText("Gửi");
}//GEN-LAST:event_btn_SendMouseEntered

    private void tf_messageInputMethodTextChanged(java.awt.event.InputMethodEvent evt) {//GEN-FIRST:event_tf_messageInputMethodTextChanged
        if(tf_message.getText().equals(""))
            btn_Send.setEnabled(false);
        else btn_Send.setEnabled(true);
    }//GEN-LAST:event_tf_messageInputMethodTextChanged

    private void btn_InviteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_InviteActionPerformed
        invite = new frmInvite();
        invite.setFriendList(client.getFriendList_State());
        invite.setUserName(username);
        invite.setGroup(lb_groupname.getText());
        invite.setVisible(true);
    }//GEN-LAST:event_btn_InviteActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        Object[] option = {"Đồng ý", "Hủy bỏ"};
        int dialogResult = JOptionPane.showOptionDialog(this, "Bạn có chắc chắn muốn thoát khỏi nhóm này?", "",JOptionPane.YES_NO_OPTION,
                JOptionPane.QUESTION_MESSAGE,null,option,option[0]);
        if(dialogResult==0){
            Connection.sendData(Command.LEAVE_GROUP+username+((char)001)+lb_groupname.getText());
            this.dispose();
        }
    }//GEN-LAST:event_formWindowClosing

    private void mni_NewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mni_NewActionPerformed
        tp_log.setText("");
    }//GEN-LAST:event_mni_NewActionPerformed
     
    public void setState(String st){
        state=st;
    }
    
    public final void setGroup(String group){
        lb_groupname.setText(group);
    }
    
    public void addMember(String user){
        model.addElement(user);
    }
    
    public void removeMember(String user){
        model.removeElement(user);
    }
    public void setUsername(String str){
        this.setTitle(str);
        username=str;       
    }
    
    // Hiển thị tin nhắn lên khung chat
    public void myMessage(String str){
        StyledDocument doc = tp_log.getStyledDocument();
        
        SimpleAttributeSet UserName = new SimpleAttributeSet();
        StyleConstants.setForeground(UserName, Color.darkGray);
        StyleConstants.setBold(UserName, true);
        
        SimpleAttributeSet normal = new SimpleAttributeSet();
        docStyle(normal, getStyle());
        try {
            doc.insertString(doc.getLength(),username+": ", UserName );
            doc.insertString(doc.getLength(), str+"\n", normal );
            new Sound().play("message");
            tp_log.select(doc.getLength(), doc.getLength());
        } catch (BadLocationException ex) {
        }
    }
    
    // Hiển thị tin nhắn nhận từ bạn
    public void friendMessage(String friendname, String style, String str){
        StyledDocument doc = tp_log.getStyledDocument();
        
        SimpleAttributeSet UserName = new SimpleAttributeSet();
        StyleConstants.setForeground(UserName, Color.BLUE);
        StyleConstants.setBold(UserName, true);
        
        SimpleAttributeSet normal = new SimpleAttributeSet();
        docStyle(normal, style);
        try {
            doc.insertString(doc.getLength(),friendname+": ", UserName );
            doc.insertString(doc.getLength(), str+"\n", normal );
            new Sound().play("message");
            tp_log.select(doc.getLength(), doc.getLength());
        } catch (BadLocationException ex) {
        }
    }
    
    // Lấy giá trị định dạng font
    public String getStyle(){
        String s="";
        if(btn_B.isSelected()){s+=1;} else s+=0;
        if(btn_I.isSelected()){s+=1;} else s+=0;
        if(btn_U.isSelected()){s+=1;} else s+=0;
        s+=String.format("%02d",cbo_font.getSelectedIndex());
        s+=String.format("%02d",cbo_size.getSelectedIndex());
        return s;
    }
    
    //Gán giá trị font cho Styleddocument
    public void docStyle(SimpleAttributeSet d, String s){
        if(s.substring(0,1).equals("0")) {
            StyleConstants.setBold(d, false);
        }
        else StyleConstants.setBold(d, true);

        if(s.substring(1,2).equals("0")) {
            StyleConstants.setItalic(d, false);
        }
        else StyleConstants.setItalic(d, true);

        if(s.substring(2,3).equals("0")) {
            StyleConstants.setUnderline(d,false);
        }
        else StyleConstants.setUnderline(d, true);

        int f=Integer.parseInt(s.substring(3,5));
        String font = (String)cbo_font.getItemAt(f);
        StyleConstants.setFontFamily(d,font);

        int idsize=Integer.parseInt(s.substring(5,7));
        int size = Integer.parseInt((String)cbo_size.getItemAt(idsize));
        StyleConstants.setFontSize(d, size);
    }
    
        
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton btn_B;
    private javax.swing.JToggleButton btn_I;
    private javax.swing.JButton btn_Invite;
    private javax.swing.JButton btn_Send;
    private javax.swing.JToggleButton btn_U;
    private javax.swing.JComboBox cbo_font;
    private javax.swing.JComboBox cbo_size;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JLabel lb_groupname;
    private javax.swing.JList ls_users;
    private javax.swing.JMenu mn_Help;
    private javax.swing.JMenu mn_chucnang;
    private javax.swing.JMenu mn_hoithoai;
    private javax.swing.JMenuItem mni_Close;
    private javax.swing.JMenuItem mni_Info;
    private javax.swing.JMenuItem mni_New;
    private javax.swing.JTextField tf_message;
    private javax.swing.JTextPane tp_log;
    // End of variables declaration//GEN-END:variables
}
